﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8" />
    <title>WashingMachine: Test/WashingMachineTest/WashingMachineTest.cs Source File</title>
    <link href="/Content/Help.css" rel="stylesheet" type="text/css" />
    <link href="/Content/css/tabs.css" rel="stylesheet" type="text/css" />
    <link href="/Content/css/doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
    <div id="header">
        <img id="logo" alt="StateForge" src="/Content/Images/StateForgeLogo.png" />
        <div id="title">
            <h1>
                C# examples using state machines generated by StateBuilderDotNet
            </h1>
            <h3>
                WashingMachine: Test/WashingMachineTest/WashingMachineTest.cs Source File
            </h3>
        </div>
        <div id="menucontainer">
            <ul id="menu">
                <li><a href="/">Home</a></li>
                <li><a href="/Home/Download">Downloads</a></li>
                <li><a href="/Help/state-machine-tools.aspx">Help</a></li>
                <li><a href="/Home/Faq">F.A.Q</a></li>
                <li><a href="/Home/About">Contact us</a></li>
            </ul>
        </div>
    </div>
<!-- Generated by Doxygen 1.7.4 -->
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="namespaces.html"><span>Namespaces</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
    </ul>
  </div>
<div class="header">
  <div class="headertitle">
<div class="title">Test/WashingMachineTest/WashingMachineTest.cs</div>  </div>
</div>
<div class="contents">
<a href="_washing_machine_test_8cs.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 ﻿
<a name="l00002"></a><a class="code" href="namespace_state_forge_1_1_examples_1_1_washing_machine.html">00002</a> <span class="keyword">namespace </span>StateForge.Examples.<a class="code" href="class_state_forge_1_1_examples_1_1_washing_machine_1_1_washing_machine.html">WashingMachine</a>
<a name="l00003"></a>00003 {
<a name="l00004"></a>00004     <span class="keyword">using</span> System;
<a name="l00005"></a>00005     <span class="keyword">using</span> NUnit.Framework;
<a name="l00006"></a>00006     <span class="keyword">using</span> StateForge.StateMachine;
<a name="l00007"></a>00007     <span class="keyword">using</span> Rhino.Mocks;
<a name="l00008"></a>00008 
<a name="l00009"></a>00009     [TestFixture]
<a name="l00010"></a><a class="code" href="class_state_forge_1_1_examples_1_1_washing_machine_1_1_washing_machine_test.html">00010</a>     <span class="keyword">class </span><a class="code" href="class_state_forge_1_1_examples_1_1_washing_machine_1_1_washing_machine_test.html">WashingMachineTest</a>
<a name="l00011"></a>00011     {
<a name="l00012"></a><a class="code" href="class_state_forge_1_1_examples_1_1_washing_machine_1_1_washing_machine_test.html#a9b0d856ba5b2dfb58a8e02049bd61d40">00012</a>         <span class="keyword">private</span> <a class="code" href="class_state_forge_1_1_examples_1_1_washing_machine_1_1_washing_machine.html">WashingMachine</a> <a class="code" href="class_state_forge_1_1_examples_1_1_washing_machine_1_1_washing_machine_test.html#a9b0d856ba5b2dfb58a8e02049bd61d40">washingMachine</a>; 
<a name="l00013"></a><a class="code" href="class_state_forge_1_1_examples_1_1_washing_machine_1_1_washing_machine_test.html#a80488c3447d54365ecab6c018b87e6ab">00013</a>         <span class="keyword">private</span> MockRepository <a class="code" href="class_state_forge_1_1_examples_1_1_washing_machine_1_1_washing_machine_test.html#a80488c3447d54365ecab6c018b87e6ab">repository</a>;
<a name="l00014"></a><a class="code" href="class_state_forge_1_1_examples_1_1_washing_machine_1_1_washing_machine_test.html#a6037610d93cb3d0544d700bf9ff95f85">00014</a>         <span class="keyword">private</span> IObserver <a class="code" href="class_state_forge_1_1_examples_1_1_washing_machine_1_1_washing_machine_test.html#a6037610d93cb3d0544d700bf9ff95f85">observer</a>;
<a name="l00015"></a><a class="code" href="class_state_forge_1_1_examples_1_1_washing_machine_1_1_washing_machine_test.html#afc21a1241e82ada52ffd0219e04b39ae">00015</a>         <span class="keyword">private</span> <span class="keyword">static</span> String contextName = <span class="stringliteral">&quot;WashingMachineContext&quot;</span>;
<a name="l00016"></a><a class="code" href="class_state_forge_1_1_examples_1_1_washing_machine_1_1_washing_machine_test.html#ac1180b80f01f1bbc8967ee61af5de5e6">00016</a>         <span class="keyword">private</span> <span class="keywordtype">string</span> current, next, <a class="code" href="class_state_forge_1_1_examples_1_1_washing_machine_1_1_washing_machine_test.html#ac1180b80f01f1bbc8967ee61af5de5e6">transition</a>;
<a name="l00017"></a>00017 
<a name="l00018"></a>00018         [SetUp]
<a name="l00019"></a><a class="code" href="class_state_forge_1_1_examples_1_1_washing_machine_1_1_washing_machine_test.html#a3c6e85700ad3ad20874e04330780feec">00019</a>         <span class="keyword">public</span> <span class="keywordtype">void</span> Setup()
<a name="l00020"></a>00020         {
<a name="l00021"></a>00021             repository = <span class="keyword">new</span> MockRepository();
<a name="l00022"></a>00022             observer = repository.StrictMock&lt;IObserver&gt;();
<a name="l00023"></a>00023             this.washingMachine = <span class="keyword">new</span> <a class="code" href="class_state_forge_1_1_examples_1_1_washing_machine_1_1_washing_machine.html">WashingMachine</a>();
<a name="l00024"></a>00024         }
<a name="l00025"></a>00025 
<a name="l00026"></a>00026         [Test]
<a name="l00027"></a><a class="code" href="class_state_forge_1_1_examples_1_1_washing_machine_1_1_washing_machine_test.html#acb753b2ac77e092c851fc004fcaf06bf">00027</a>         <span class="keyword">public</span> <span class="keywordtype">void</span> EvStart_EvFault_EvDiagnoseSuccess_EvWashingDone()
<a name="l00028"></a>00028         {
<a name="l00029"></a>00029             this.washingMachine.Observer = observer;
<a name="l00030"></a>00030 
<a name="l00031"></a>00031             <span class="keyword">using</span> (repository.Record())
<a name="l00032"></a>00032             {
<a name="l00033"></a>00033                 <span class="keyword">using</span> (repository.Ordered())
<a name="l00034"></a>00034                 {
<a name="l00035"></a>00035                     <span class="comment">// this.washingMachine.Start();</span>
<a name="l00036"></a>00036                     current = <span class="stringliteral">&quot;Idle&quot;</span>; next = <span class="stringliteral">&quot;Washing&quot;</span>; transition = <span class="stringliteral">&quot;Start&quot;</span>;
<a name="l00037"></a>00037                     Expect.Call(() =&gt; this.observer.OnTransitionBegin(contextName, current, next, transition));
<a name="l00038"></a>00038                     Expect.Call(() =&gt; this.observer.OnExit(contextName, current));
<a name="l00039"></a>00039                     Expect.Call(() =&gt; this.observer.OnEntry(contextName, <span class="stringliteral">&quot;Running&quot;</span>));
<a name="l00040"></a>00040                     Expect.Call(() =&gt; this.observer.OnEntry(contextName, next));
<a name="l00041"></a>00041                     Expect.Call(() =&gt; this.observer.OnTransitionEnd(contextName, current, next, transition));
<a name="l00042"></a>00042 
<a name="l00043"></a>00043                     <span class="comment">//this.washingMachine.Fault();</span>
<a name="l00044"></a>00044                     current = <span class="stringliteral">&quot;Washing&quot;</span>; next = <span class="stringliteral">&quot;OutOfService&quot;</span>; transition = <span class="stringliteral">&quot;Fault&quot;</span>;
<a name="l00045"></a>00045                     Expect.Call(() =&gt; this.observer.OnTransitionBegin(contextName, current, next, transition));
<a name="l00046"></a>00046                     Expect.Call(() =&gt; this.observer.OnExit(contextName, current));
<a name="l00047"></a>00047                     Expect.Call(() =&gt; this.observer.OnExit(contextName, <span class="stringliteral">&quot;Running&quot;</span>));
<a name="l00048"></a>00048                     Expect.Call(() =&gt; this.observer.OnEntry(contextName, next));
<a name="l00049"></a>00049                     Expect.Call(() =&gt; this.observer.OnTransitionEnd(contextName, current, next, transition));
<a name="l00050"></a>00050 
<a name="l00051"></a>00051                     <span class="comment">//this.washingMachine.DiagnoseSuccess();</span>
<a name="l00052"></a>00052                     current = <span class="stringliteral">&quot;OutOfService&quot;</span>; next = <span class="stringliteral">&quot;Washing&quot;</span>; transition = <span class="stringliteral">&quot;DiagnoseSuccess&quot;</span>;
<a name="l00053"></a>00053                     Expect.Call(() =&gt; this.observer.OnTransitionBegin(contextName, current, next, transition));
<a name="l00054"></a>00054                     Expect.Call(() =&gt; this.observer.OnExit(contextName, current));
<a name="l00055"></a>00055                     Expect.Call(() =&gt; this.observer.OnEntry(contextName, <span class="stringliteral">&quot;Running&quot;</span>));
<a name="l00056"></a>00056                     Expect.Call(() =&gt; this.observer.OnEntry(contextName, next));
<a name="l00057"></a>00057                     Expect.Call(() =&gt; this.observer.OnTransitionEnd(contextName, current, next, transition));
<a name="l00058"></a>00058 
<a name="l00059"></a>00059                     <span class="comment">//this.washingMachine.WashingDone();</span>
<a name="l00060"></a>00060                     current = <span class="stringliteral">&quot;Washing&quot;</span>; next = <span class="stringliteral">&quot;Rinsing&quot;</span>; transition = <span class="stringliteral">&quot;WashingDone&quot;</span>;
<a name="l00061"></a>00061                     Expect.Call(() =&gt; this.observer.OnTransitionBegin(contextName, current, next, transition));
<a name="l00062"></a>00062                     Expect.Call(() =&gt; this.observer.OnExit(contextName, current));
<a name="l00063"></a>00063                     Expect.Call(() =&gt; this.observer.OnEntry(contextName, next));
<a name="l00064"></a>00064                     Expect.Call(() =&gt; this.observer.OnTransitionEnd(contextName, current, next, transition));
<a name="l00065"></a>00065                 }
<a name="l00066"></a>00066             }
<a name="l00067"></a>00067 
<a name="l00068"></a>00068             <span class="keyword">using</span> (repository.Playback())
<a name="l00069"></a>00069             {
<a name="l00070"></a>00070                 this.washingMachine.Start();
<a name="l00071"></a>00071                 this.washingMachine.Fault();
<a name="l00072"></a>00072                 this.washingMachine.DiagnoseSuccess();
<a name="l00073"></a>00073                 this.washingMachine.WashingDone();
<a name="l00074"></a>00074             }
<a name="l00075"></a>00075         }
<a name="l00076"></a>00076         [Test]
<a name="l00077"></a><a class="code" href="class_state_forge_1_1_examples_1_1_washing_machine_1_1_washing_machine_test.html#a5b701a48749dce19c917d4fb7e3b163d">00077</a>         <span class="keyword">public</span> <span class="keywordtype">void</span> EvStart_EvWashingDone_EvFault_EvDiagnoseSuccess_EvRinsingDone()
<a name="l00078"></a>00078         {
<a name="l00079"></a>00079             this.washingMachine.Start();
<a name="l00080"></a>00080             this.washingMachine.Observer = observer;
<a name="l00081"></a>00081 
<a name="l00082"></a>00082             <span class="keyword">using</span> (repository.Record())
<a name="l00083"></a>00083             {
<a name="l00084"></a>00084                 <span class="keyword">using</span> (repository.Ordered())
<a name="l00085"></a>00085                 {
<a name="l00086"></a>00086                     <span class="comment">//this.washingMachine.WashingDone();</span>
<a name="l00087"></a>00087                     current = <span class="stringliteral">&quot;Washing&quot;</span>; next = <span class="stringliteral">&quot;Rinsing&quot;</span>; transition = <span class="stringliteral">&quot;WashingDone&quot;</span>;
<a name="l00088"></a>00088                     Expect.Call(() =&gt; this.observer.OnTransitionBegin(contextName, current, next, transition));
<a name="l00089"></a>00089                     Expect.Call(() =&gt; this.observer.OnExit(contextName, current));
<a name="l00090"></a>00090                     Expect.Call(() =&gt; this.observer.OnEntry(contextName, next));
<a name="l00091"></a>00091                     Expect.Call(() =&gt; this.observer.OnTransitionEnd(contextName, current, next, transition));
<a name="l00092"></a>00092 
<a name="l00093"></a>00093                     <span class="comment">//this.washingMachine.Fault();</span>
<a name="l00094"></a>00094                     current = <span class="stringliteral">&quot;Rinsing&quot;</span>; next = <span class="stringliteral">&quot;OutOfService&quot;</span>; transition = <span class="stringliteral">&quot;Fault&quot;</span>;
<a name="l00095"></a>00095                     Expect.Call(() =&gt; this.observer.OnTransitionBegin(contextName, current, next, transition));
<a name="l00096"></a>00096                     Expect.Call(() =&gt; this.observer.OnExit(contextName, current));
<a name="l00097"></a>00097                     Expect.Call(() =&gt; this.observer.OnExit(contextName, <span class="stringliteral">&quot;Running&quot;</span>));
<a name="l00098"></a>00098                     Expect.Call(() =&gt; this.observer.OnEntry(contextName, next));
<a name="l00099"></a>00099                     Expect.Call(() =&gt; this.observer.OnTransitionEnd(contextName, current, next, transition));
<a name="l00100"></a>00100 
<a name="l00101"></a>00101                     <span class="comment">//this.washingMachine.DiagnoseSuccess();</span>
<a name="l00102"></a>00102                     current = <span class="stringliteral">&quot;OutOfService&quot;</span>; next = <span class="stringliteral">&quot;Rinsing&quot;</span>; transition = <span class="stringliteral">&quot;DiagnoseSuccess&quot;</span>;
<a name="l00103"></a>00103                     Expect.Call(() =&gt; this.observer.OnTransitionBegin(contextName, current, next, transition));
<a name="l00104"></a>00104                     Expect.Call(() =&gt; this.observer.OnExit(contextName, current));
<a name="l00105"></a>00105                     Expect.Call(() =&gt; this.observer.OnEntry(contextName, <span class="stringliteral">&quot;Running&quot;</span>));
<a name="l00106"></a>00106                     Expect.Call(() =&gt; this.observer.OnEntry(contextName, next));
<a name="l00107"></a>00107                     Expect.Call(() =&gt; this.observer.OnTransitionEnd(contextName, current, next, transition));
<a name="l00108"></a>00108 
<a name="l00109"></a>00109                     <span class="comment">//this.washingMachine.RinsingDone();</span>
<a name="l00110"></a>00110                     current = <span class="stringliteral">&quot;Rinsing&quot;</span>; next = <span class="stringliteral">&quot;Spinning&quot;</span>; transition = <span class="stringliteral">&quot;RinsingDone&quot;</span>;
<a name="l00111"></a>00111                     Expect.Call(() =&gt; this.observer.OnTransitionBegin(contextName, current, next, transition));
<a name="l00112"></a>00112                     Expect.Call(() =&gt; this.observer.OnExit(contextName, current));
<a name="l00113"></a>00113                     Expect.Call(() =&gt; this.observer.OnEntry(contextName, next));
<a name="l00114"></a>00114                     Expect.Call(() =&gt; this.observer.OnTransitionEnd(contextName, current, next, transition));
<a name="l00115"></a>00115                 }
<a name="l00116"></a>00116             }
<a name="l00117"></a>00117 
<a name="l00118"></a>00118             <span class="keyword">using</span> (repository.Playback())
<a name="l00119"></a>00119             {
<a name="l00120"></a>00120                 this.washingMachine.WashingDone();
<a name="l00121"></a>00121                 this.washingMachine.Fault();
<a name="l00122"></a>00122                 this.washingMachine.DiagnoseSuccess();
<a name="l00123"></a>00123                 this.washingMachine.RinsingDone();
<a name="l00124"></a>00124             }
<a name="l00125"></a>00125         }
<a name="l00126"></a>00126 
<a name="l00127"></a>00127         [Test]
<a name="l00128"></a><a class="code" href="class_state_forge_1_1_examples_1_1_washing_machine_1_1_washing_machine_test.html#a89ce9f7fbdcedb63c9d0c159f295cd84">00128</a>         <span class="keyword">public</span> <span class="keywordtype">void</span> EvStart_EvWashingDone_EvRinsingDone_EvFault_EvDiagnoseSuccess_EvSpinningDone()
<a name="l00129"></a>00129         {
<a name="l00130"></a>00130             this.washingMachine.Start();
<a name="l00131"></a>00131             this.washingMachine.WashingDone();
<a name="l00132"></a>00132             this.washingMachine.Observer = observer;
<a name="l00133"></a>00133 
<a name="l00134"></a>00134             <span class="keyword">using</span> (repository.Record())
<a name="l00135"></a>00135             {
<a name="l00136"></a>00136                 <span class="keyword">using</span> (repository.Ordered())
<a name="l00137"></a>00137                 {
<a name="l00138"></a>00138                     <span class="comment">//this.washingMachine.RinsingDone();</span>
<a name="l00139"></a>00139                     current = <span class="stringliteral">&quot;Rinsing&quot;</span>; next = <span class="stringliteral">&quot;Spinning&quot;</span>; transition = <span class="stringliteral">&quot;RinsingDone&quot;</span>;
<a name="l00140"></a>00140                     Expect.Call(() =&gt; this.observer.OnTransitionBegin(contextName, current, next, transition));
<a name="l00141"></a>00141                     Expect.Call(() =&gt; this.observer.OnExit(contextName, current));
<a name="l00142"></a>00142                     Expect.Call(() =&gt; this.observer.OnEntry(contextName, next));
<a name="l00143"></a>00143                     Expect.Call(() =&gt; this.observer.OnTransitionEnd(contextName, current, next, transition));
<a name="l00144"></a>00144 
<a name="l00145"></a>00145                     <span class="comment">//this.washingMachine.Fault();</span>
<a name="l00146"></a>00146                     current = <span class="stringliteral">&quot;Spinning&quot;</span>; next = <span class="stringliteral">&quot;OutOfService&quot;</span>; transition = <span class="stringliteral">&quot;Fault&quot;</span>;
<a name="l00147"></a>00147                     Expect.Call(() =&gt; this.observer.OnTransitionBegin(contextName, current, next, transition));
<a name="l00148"></a>00148                     Expect.Call(() =&gt; this.observer.OnExit(contextName, current));
<a name="l00149"></a>00149                     Expect.Call(() =&gt; this.observer.OnExit(contextName, <span class="stringliteral">&quot;Running&quot;</span>));
<a name="l00150"></a>00150                     Expect.Call(() =&gt; this.observer.OnEntry(contextName, next));
<a name="l00151"></a>00151                     Expect.Call(() =&gt; this.observer.OnTransitionEnd(contextName, current, next, transition));
<a name="l00152"></a>00152 
<a name="l00153"></a>00153                     <span class="comment">//this.washingMachine.DiagnoseSuccess();</span>
<a name="l00154"></a>00154                     current = <span class="stringliteral">&quot;OutOfService&quot;</span>; next = <span class="stringliteral">&quot;Spinning&quot;</span>; transition = <span class="stringliteral">&quot;DiagnoseSuccess&quot;</span>;
<a name="l00155"></a>00155                     Expect.Call(() =&gt; this.observer.OnTransitionBegin(contextName, current, next, transition));
<a name="l00156"></a>00156                     Expect.Call(() =&gt; this.observer.OnExit(contextName, current));
<a name="l00157"></a>00157                     Expect.Call(() =&gt; this.observer.OnEntry(contextName, <span class="stringliteral">&quot;Running&quot;</span>));
<a name="l00158"></a>00158                     Expect.Call(() =&gt; this.observer.OnEntry(contextName, next));
<a name="l00159"></a>00159                     Expect.Call(() =&gt; this.observer.OnTransitionEnd(contextName, current, next, transition));
<a name="l00160"></a>00160 
<a name="l00161"></a>00161                     <span class="comment">//this.washingMachine.SpinningDone();</span>
<a name="l00162"></a>00162                     current = <span class="stringliteral">&quot;Spinning&quot;</span>; next = <span class="stringliteral">&quot;End&quot;</span>; transition = <span class="stringliteral">&quot;SpinningDone&quot;</span>;
<a name="l00163"></a>00163                     Expect.Call(() =&gt; this.observer.OnTransitionBegin(contextName, current, next, transition));
<a name="l00164"></a>00164                     Expect.Call(() =&gt; this.observer.OnExit(contextName, current));
<a name="l00165"></a>00165                     Expect.Call(() =&gt; this.observer.OnExit(contextName, <span class="stringliteral">&quot;Running&quot;</span>));
<a name="l00166"></a>00166                     Expect.Call(() =&gt; this.observer.OnEntry(contextName, next));
<a name="l00167"></a>00167                     Expect.Call(() =&gt; this.observer.OnTransitionEnd(contextName, current, next, transition));
<a name="l00168"></a>00168                 }
<a name="l00169"></a>00169             }
<a name="l00170"></a>00170 
<a name="l00171"></a>00171             <span class="keyword">using</span> (repository.Playback())
<a name="l00172"></a>00172             {
<a name="l00173"></a>00173                 this.washingMachine.RinsingDone();
<a name="l00174"></a>00174                 this.washingMachine.Fault();
<a name="l00175"></a>00175                 this.washingMachine.DiagnoseSuccess();
<a name="l00176"></a>00176                 this.washingMachine.SpinningDone();
<a name="l00177"></a>00177             }
<a name="l00178"></a>00178         }
<a name="l00179"></a>00179     }
<a name="l00180"></a>00180 }
</pre></div></div>
</div>
﻿<div id="footer">
    <hr />
    <p>
        Copyright &copy; 2011 StateForge.</p>
    <hr />
</div>
</body> </html> 
